package com.rp.system.user.model;

import com.rp.system.user.entity.SysPermission;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.*;

/**
 * 类说明:
 *
 * @author ****
 * @date 2020-12-15 11:17  新建
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value = "权限页面展示", description = "")
public class SysPermissionTree implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "id",hidden = true)
    private String id;
    @ApiModelProperty(value = "是否叶子节点: 1:是 0:不是",hidden = true)
    private Integer isLeaf;

    @ApiModelProperty(value = "菜单名称")
    private String name;
    @ApiModelProperty(value = "跳转网页链接")
    private String path;
    @ApiModelProperty(value = "是否隐藏路由菜单: 0否,1是（默认值0）")
    private Boolean hidden;
    @ApiModelProperty(value = "一级菜单跳转地址")
    private String redirect;
    @ApiModelProperty(value = "组件")
    private String component;
    @ApiModelProperty(value = "alwaysShow")
    private Integer alwaysShow;

    @ApiModelProperty(value = "meta")
    private Meta meta;
    @ApiModelProperty(value = "子节点列表")
    private LinkedHashSet<SysPermissionTree> children;


    public SysPermissionTree() {

    }

    public SysPermissionTree(String id,Integer isLeaf, String name, String path, Boolean hidden, String redirect, String component, Integer alwaysShow,
                             String title, String icon, Boolean noCache) {
        this.id = id;
        this.isLeaf = isLeaf;
        this.name = name;
        this.path = path;
        this.hidden = hidden;
        this.redirect = redirect;
        this.component = component;
        this.alwaysShow = alwaysShow;
        this.meta = new Meta();
        this.meta.title = title;
        this.meta.icon = icon;
        this.meta.noCache = noCache;

    }

    public SysPermissionTree(SysPermission permission) {
        this.id = permission.getId();
        this.isLeaf = permission.getIsLeaf();
        this.name = permission.getComponentName();
        this.path = permission.getUrl();
        this.hidden = permission.getHidden();
        this.component = permission.getComponent();
        this.alwaysShow = permission.getAlwaysShow();
        this.meta = new Meta();
        this.meta.title = permission.getName();
        this.meta.icon = permission.getIcon();
        if(permission.getKeepAlive()==1){
            this.meta.noCache = true;
        }
    }

}

@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
class Meta{
    @ApiModelProperty(value = "标题")
     String title;
    @ApiModelProperty(value = "菜单图标")
     String icon;
    @ApiModelProperty(value = "缓存")
     Boolean noCache = false;
}
